cd ""
set more off
set matsize 1600


//////////////////////// //////////////////////// //////////////////////// 
//////////////////////// Table 2
//////////////////////// //////////////////////// //////////////////////// 

// Note: Each time series ends in t+1 to avoid bias from downstream legal changes 

***** Switzerland
use "./Datasets/Other/Swiss_master.dta",clear
xtset bfsnr year
keep if (reformyear <= 1)  // t+1
sum pctforeign if F1.diff_voteright_following==1
local mean = `r(mean)'

// Uncomment to focus on restrictive subset:
//keep if yesref <= .5 & cantonid!=25

// Main spec
qui: xtreg log_net_welfare_head vf interaction_constant pctforeign ///
regunemployed_pop lowbracket_rate sp log_rev c.logpop##c.year  c.year##i.cantonid i.year, fe cl(bfsnr)
nlcom  100*(_b[vf] + `mean'*_b[interaction_constant] ), noheader post
est store S1

// Dropping population outliers
centile pop if F1.diff_voteright_following==1,c(10 90)
qui: xtreg log_net_welfare_head  vf interaction_constant pctforeign ///
	regunemployed_pop lowbracket_rate sp log_rev c.logpop##c.year  c.year##i.cantonid i.year if pop > `r(c_1)' & pop < `r(c_2)', fe cl(bfsnr)
nlcom  100*(_b[vf] + `mean'*_b[interaction_constant] ), noheader post
est store S2

// No covars
qui: xtreg log_net_welfare_head  vf interaction_constant pctforeign ///
	c.logpop##c.year  c.year##i.cantonid i.year, fe cl(bfsnr)
nlcom  100*(_b[vf] + `mean'*_b[interaction_constant] ), noheader post
est store S3

// Regional Quad TT
qui: xtreg log_net_welfare_head vf interaction_constant pctforeign ///
regunemployed_pop lowbracket_rate sp log_rev c.logpop##c.year c.year##c.year##i.regional_id i.year, fe cl(bfsnr)
nlcom  100*(_b[vf] + `mean'*_b[interaction_constant] ), noheader post
est store S4

estout S1 S2 S3 S4, cells(b(fmt(2)) se(fmt(2)par))  style(tex)
	

// Placebo 
gen vlag1 = 0
replace vlag1 = 1 if reformyear>= -1
gen lag1 = pctforeign_fixed * vlag1
replace lag1 = L1.lag1 if reformyear >= 0

gen vlag2 = 0
replace vlag2 = 1 if reformyear>=-2
gen lag2 = pctforeign_fixed * vlag2
replace lag2 = L1.lag2 if reformyear>=-1

gen vlag3 = 0
replace vlag3 = 1 if reformyear>=-3 
gen lag3 = pctforeign_fixed * vlag3
replace lag3 = L1.lag3 if reformyear>=-2

gen vlag4 = 0
replace vlag4 = 1 if reformyear>=-4
gen lag4 = pctforeign_fixed * vlag4
replace lag4 = L1.lag4 if reformyear>=-3


foreach i of numlist 1 2 3 4 {
		local z = `i'
		qui: xtreg  log_net_welfare_head vf interaction_constant  vlag1 vlag2 vlag3 vlag4 lag1 lag2  lag3 lag4  ///
		log_rev pctforeign lowbracket_rate regunemployed_pop   ///
		sp c.logpop##c.year  c.year##i.cantonid i.year, fe cl(bfsnr)
		qui:nlcom  100*(_b[vlag`i'] + `mean'*_b[lag`i'])  , noheader post	
		est store q`z'
}
	
estout q1 q2 q3 q4, cells(b(fmt(2)) se(fmt(2)par))  style(tex)



**** Belgium 

// Note: The treatment year indicator (vf) is collinear in the Belgian specification since all municipalities are treated 
// and the specification includes dummies for each year. 

use "./Datasets/Other/Belgium_master.dta", clear
xtset id year
keep if year<=2006 // t+1

sum pctnoneunoncit if year==2004
local mean = `r(mean)'

// Uncomment to focus on restrictive subset:
// keep if flanders_wide==1


// Main Spec
qui: xtreg log_cpas_head vf main_interaction filing_rate pctnoneunoncit  ///
socshare log_unemp_rate log_rev c.logpop##c.year  i.year  , fe cl(id)
nlcom  100*(_b[vf] + `mean'*_b[main_interaction]), noheader post
est store B1

// Dropping small municipaliites
qui: centile population if year==2004, c(10 90)
qui: xtreg log_cpas_head  vf main_interaction pctnoneunoncit  ///
socshare log_unemp_rate log_rev c.logpop##c.year  i.year if population > `r(c_1)' & population < `r(c_2)' , fe cl(id)
nlcom  100*(_b[vf] + `mean'*_b[main_interaction]), noheader post
est store B2

// No Covars
qui: xtreg log_cpas_head vf main_interaction  ///
c.logpop##c.year   i.year, fe cl(id)
nlcom  100*(_b[vf] + `mean'*_b[main_interaction]), noheader post
est store B3

// Regional Quad TT
qui: xtreg log_cpas_head vf main_interaction  ///
socshare log_unemp_rate log_rev  c.logpop##c.year i.regionid##c.year##c.year  i.year, fe cl(id)
nlcom  100*(_b[vf] + `mean'*_b[main_interaction]), noheader post
est store B4

estout B1 B2 B3 B4, cells(b(fmt(2)) se(fmt(2)par))  style(tex)

// Placebo 
gen lag1 = 0
replace lag1 = pctnoneunoncit if year >= 2004
replace lag1 = L1.lag1 if year >= 2005
gen lag2 = 0
replace lag2 = pctnoneunoncit if year >= 2003
replace lag2 = L1.lag2 if year >= 2004
gen lag3 = 0
replace lag3 = pctnoneunoncit if year >= 2002
replace lag3 = L1.lag3 if year >= 2003
gen lag4 = 0
replace lag4 = pctnoneunoncit if year >= 2001
replace lag4 = L1.lag4 if year >= 2002

foreach i of numlist 1 2 3  4{
		local z = `i'
		qui: xtreg  log_cpas_head main_interaction main_interaction lag1 lag2 lag3 lag4 pctnoneunoncit filing_rate log_unemp_rate socshare log_rev i.year c.logpop##c.year i.regionid##c.year##c.year, fe cl(id)
		qui: nlcom  100*(`mean'*_b[lag`i'])  , noheader post
		est store q`z'
}
	
estout q1 q2 q3 q4, cells(b(fmt(2)) se(fmt(2)par))  style(tex)



//////////////////////// //////////////////////// //////////////////////// 
//////////////////////// Table B4 - Marginal Effects (per capita)
//////////////////////// //////////////////////// //////////////////////// 

***** Switzerland
use "./Datasets/Other/Swiss_master.dta",clear
xtset bfsnr year
keep if (reformyear <= 1)  

qui: xtreg net_welfare_head vf interaction_constant pctforeign ///
regunemployed_pop lowbracket_rate sp log_rev c.logpop##c.year  c.year##i.cantonid i.year, fe cl(bfsnr)
nlcom  (.01*_b[interaction_constant] ), noheader post
est store S1

centile pop if F1.diff_voteright_following==1,c(10 90)
qui: xtreg net_welfare_head  vf interaction_constant pctforeign ///
	regunemployed_pop lowbracket_rate sp log_rev c.logpop##c.year   c.year##i.cantonid i.year if pop > `r(c_1)' & pop < `r(c_2)', fe cl(bfsnr)
nlcom  (.01*_b[interaction_constant] ), noheader post
est store S2

qui: xtreg net_welfare_head  vf interaction_constant pctforeign ///
 c.logpop##c.year  c.year##i.cantonid i.year, fe cl(bfsnr)
nlcom  (.01*_b[interaction_constant] ), noheader post
est store S3

qui: xtreg net_welfare_head vf interaction_constant pctforeign ///
regunemployed_pop lowbracket_rate sp log_rev c.logpop##c.year c.year##c.year#i.regional_id i.year, fe cl(bfsnr)
nlcom  (.01*_b[interaction_constant] ), noheader post
est store S4

estout S1 S2 S3 S4, cells(b(fmt(2)) se(fmt(2)par))  style(tex)
	

// Placebo 
gen vlag1 = 0
replace vlag1 = 1 if reformyear>= -1
gen lag1 = pctforeign_fixed * vlag1
replace lag1 = L1.lag1 if reformyear >= 0

gen vlag2 = 0
replace vlag2 = 1 if reformyear>=-2
gen lag2 = pctforeign_fixed * vlag2
replace lag2 = L1.lag2 if reformyear>=-1

gen vlag3 = 0
replace vlag3 = 1 if reformyear>=-3 
gen lag3 = pctforeign_fixed * vlag3
replace lag3 = L1.lag3 if reformyear>=-2

gen vlag4 = 0
replace vlag4 = 1 if reformyear>=-4
gen lag4 = pctforeign_fixed * vlag4
replace lag4 = L1.lag4 if reformyear>=-3


foreach i of numlist 1 2 3 4 {
		local z = `i'
		qui: xtreg  net_welfare_head vf interaction_constant  vlag1 vlag2 vlag3 vlag4 lag1 lag2  lag3 lag4  ///
		log_rev pctforeign lowbracket_rate regunemployed_pop   ///
		sp  c.logpop##c.year c.year##i.cantonid i.year, fe cl(bfsnr)
		qui:nlcom  (.01*_b[lag`i'])  , noheader post	
		est store q`z'
}
	
estout q1 q2 q3 q4, cells(b(fmt(2)) se(fmt(2)par))  style(tex)



**** Belgium 

use "./Datasets/Other/Belgium_master.dta", clear
xtset id year
keep if year<=2006 

// Main Spec
qui: xtreg cpas_head main_interaction filing_rate pctnoneunoncit  ///
socshare log_unemp_rate log_rev c.logpop##c.year  i.year  , fe cl(id)
nlcom  (.01*_b[main_interaction]), noheader post
est store B1

// Population trim
qui: centile population if year==2004, c(10 90)
qui: xtreg cpas_head  main_interaction pctnoneunoncit  ///
socshare log_unemp_rate log_rev c.logpop##c.year  i.year if population > `r(c_1)' & population < `r(c_2)' , fe cl(id)
nlcom  (.01*_b[main_interaction]), noheader post
est store B2

// No Covars
qui: xtreg cpas_head main_interaction  ///
c.logpop##c.year   i.year, fe cl(id)
nlcom  (.01*_b[main_interaction]), noheader post
est store B3

// Regional Quad TT
qui: xtreg cpas_head main_interaction  ///
socshare log_unemp_rate log_rev  c.logpop##c.year i.regionid##c.year##c.year  i.year, fe cl(id)
nlcom  (.01*_b[main_interaction]), noheader post
est store B4

estout B1 B2 B3 B4, cells(b(fmt(2)) se(fmt(2)par))  style(tex)

// Placebo 
gen lag1 = 0
replace lag1 = pctnoneunoncit if year >= 2004
replace lag1 = L1.lag1 if year >= 2005
gen lag2 = 0
replace lag2 = pctnoneunoncit if year >= 2003
replace lag2 = L1.lag2 if year >= 2004
gen lag3 = 0
replace lag3 = pctnoneunoncit if year >= 2002
replace lag3 = L1.lag3 if year >= 2003
gen lag4 = 0
replace lag4 = pctnoneunoncit if year >= 2001
replace lag4 = L1.lag4 if year >= 2002

foreach i of numlist 1 2 3  4{
		local z = `i'
		qui: xtreg  cpas_head main_interaction lag1 lag2 lag3 lag4 pctnoneunoncit filing_rate log_unemp_rate socshare log_rev i.year c.logpop##c.year i.regionid##c.year##c.year, fe cl(id)
		qui: nlcom  .01*_b[lag`i']  , noheader post
		est store q`z'
}
	
estout q1 q2 q3 q4, cells(b(fmt(2)) se(fmt(2)par))  style(tex)


//////////////////////// //////////////////////// //////////////////////// 
//////////////////////// Table B5 - Bins
//////////////////////// //////////////////////// //////////////////////// 


est drop _all
use "./Datasets/Other/Swiss_master.dta",clear
keep if (reformyear <= 0) 
xtset bfsnr year
keep if pop >250 // Remove hamlets to avoid overweighting

qui:xtreg log_net_welfare_head c.vf##i.foreignbin  pctforeign ///
regunemployed_pop lowbracket_rate sp log_rev c.logpop##c.year c.year##c.year##i.cantonid  i.year, fe cl(bfsnr)
nlcom (100*( _b[c.vf#2.foreignbin])) (100*(_b[c.vf#3.foreignbin])),noheader post
est store S3_1

qui: xtreg log_net_welfare_head c.vf##i.foreignbin4  pctforeign ///
regunemployed_pop lowbracket_rate sp log_rev c.logpop##c.year c.year##c.year##i.cantonid i.year, fe cl(bfsnr)
nlcom (100*( _b[c.vf#2.foreignbin])) (100*(_b[c.vf#3.foreignbin]))  (100*(_b[c.vf#4.foreignbin])),noheader post
est store S4_1


use "./Datasets/Other/Belgium_master.dta",clear
xtset id year
keep if year<=2005

qui: xtreg log_cpas_head  c.vf##i.foreignbin pctnoneunoncit  ///
socshare log_unemp_rate log_rev filing_rate c.logpop##c.year  i.year, fe cl(id)
nlcom   (100*(_b[c.vf#2.foreignbin])) (100*(_b[c.vf#3.foreignbin])) ,noheader post
est store B3_1

qui: xtreg log_cpas_head  c.vf##i.foreignbin4 pctnoneunoncit  ///
socshare log_unemp_rate log_rev filing_rate c.logpop##c.year  i.year, fe cl(id)
nlcom   (100*(_b[c.vf#2.foreignbin])) (100*(_b[c.vf#3.foreignbin])) (100*(_b[c.vf#4.foreignbin])) ,noheader post
est store B4_1


// Marginal effects
estout S3_* B3_*, cells(b(fmt(2)) se(fmt(2)par))  style(tex)
estout S4_* B4_*, cells(b(fmt(2)) se(fmt(2)par))  style(tex)
						




//////////////////////// //////////////////////// //////////////////////// 
//////////////////////// Table B6 - Lagged poverty and unemp.
//////////////////////// //////////////////////// //////////////////////// 

***** Switzerland
use "./Datasets/Other/Swiss_master.dta",clear
xtset bfsnr year
keep if (reformyear <= 1) 

sum pctforeign if F1.diff_voteright_following==1
local mean = `r(mean)'

// Main spec
qui: xtreg log_net_welfare_head vf interaction_constant pctforeign ///
regunemployed_pop lowbracket_rate sp log_rev L1.lowbracket_rate L1.regunemployed_pop c.logpop##c.year  c.year##i.cantonid i.year, fe cl(bfsnr)
nlcom  100*(_b[vf] + `mean'*_b[interaction_constant] ), noheader post
est store S1

// Dropping population outliers
centile pop if F1.diff_voteright_following==1,c(10 90)
qui: xtreg log_net_welfare_head  vf interaction_constant pctforeign ///
	regunemployed_pop lowbracket_rate sp log_rev L1.lowbracket_rate L1.regunemployed_pop  c.logpop##c.year c.year##i.cantonid i.year if pop > `r(c_1)' & pop < `r(c_2)', fe cl(bfsnr)
nlcom  100*(_b[vf] + `mean'*_b[interaction_constant] ), noheader post
est store S2

// Regional Quad TT
qui: xtreg log_net_welfare_head vf interaction_constant pctforeign ///
regunemployed_pop lowbracket_rate sp log_rev L1.lowbracket_rate L1.regunemployed_pop  c.logpop##c.year c.year##c.year##i.regional_id i.year, fe cl(bfsnr)
nlcom  100*(_b[vf] + `mean'*_b[interaction_constant] ), noheader post
est store S3

estout S1 S2 S3, cells(b(fmt(2)) se(fmt(2)par))  style(tex)
	

**** Belgium 


use "./Datasets/Other/Belgium_master.dta", clear
xtset id year
keep if year<=2006

sum pctnoneunoncit if year==2004
local mean = `r(mean)'

// Main Spec
qui: xtreg log_cpas_head vf main_interaction filing_rate pctnoneunoncit  ///
socshare log_unemp_rate log_rev c.logpop##c.year  i.year, fe cl(id)
nlcom  100*(_b[vf] + `mean'*_b[main_interaction]), noheader post
est store B1

// Dropping population outliers
qui: centile population if year==2004, c(10 90)
qui: xtreg log_cpas_head  vf main_interaction pctnoneunoncit  ///
socshare log_unemp_rate log_rev L1.log_unemp_rate L1.filing_rate  c.logpop##c.year  i.year if population > `r(c_1)' & population < `r(c_2)', fe cl(id)
nlcom  100*(_b[vf] + `mean'*_b[main_interaction]), noheader post
est store B2

// Regional Quad TT
qui: xtreg log_cpas_head vf main_interaction  ///
socshare log_unemp_rate log_rev L1.log_unemp_rate L1.filing_rate c.logpop##c.year i.regionid##c.year##c.year  i.year, fe cl(id)
nlcom  100*(_b[vf] + `mean'*_b[main_interaction]), noheader post
est store B3

estout B1 B2 B3, cells(b(fmt(2)) se(fmt(2)par))  style(tex)


						
//////////////////////// //////////////////////// //////////////////////// 
//////////////////////// Table B7  - Terms
//////////////////////// //////////////////////// //////////////////////// 

// Switzerland

use "./Datasets/Other/Swiss_master.dta",clear
gen term = .
replace term = 0 if (cantonid==10) & (year>=2002 & year <= 2003)
replace term = 1 if (cantonid==10) & (year>=2007 & year <= 2008)
replace term = 0 if (cantonid==25) & (year>=2004 & year <= 2005)
replace term = 1 if (cantonid==25) & (year>=2008 & year <= 2009)

replace net_welfare_head = net_welfare_head/ (priceindex/100)
collapse (mean) net_welfare_head pctforeign regunemployed_pop lowbracket_rate foreignbin logpop log_rev, by(term bfsnr cantonid)
drop if term==.
xtset bfsnr term

gen log_net_welfare_head = log(net_welfare_head)

reg D1.log_net_welfare_head i.foreignbin D1.pctforeign D1.regunemployed_pop D1.lowbracket_rate D1.logpop i.cantonid  if cantonid!=22, robust

nlcom 100*(_b[_cons] + _b[1.foreignbin])
nlcom 100*(_b[_cons] + _b[2.foreignbin])
nlcom 100*(_b[_cons] + _b[3.foreignbin])

reg D1.log_net_welfare_head pctforeign D1.regunemployed_pop D1.lowbracket_rate D1.logpop   if cantonid!=22, robust

// Belgium

use "./Datasets/Other/Belgium_master.dta", clear
xtset id year
	
gen term = .
replace term = 0 if  (year>=2001 & year <= 2002)
replace term = 1 if  (year>=2007 & year <= 2008)
collapse (mean) cpas_head filing_rate unemp_rate pctnoneunoncit foreignbin4 foreignbin logpop log_rev, by(term id)

drop if term==.
xtset id term 

gen log_cpas_head = log(cpas_head)

reg D1.log_cpas_head i.foreignbin D1.pctnoneunoncit D1.filing_rate D1.unemp_rate D1.logpop, robust

nlcom 100*(_b[_cons] + _b[1.foreignbin])
nlcom 100*(_b[_cons] + _b[2.foreignbin])
nlcom 100*(_b[_cons] + _b[3.foreignbin])


reg D1.log_cpas_head c.pctnoneunoncit D1.filing_rate D1.unemp_rate D1.logpop, robust



//////////////////////// //////////////////////// ////////////////////////// 
//////////////////////// Table B8 - Swiss cantonal drop
//////////////////////// //////////////////////// //////////////////////// 


use "./Datasets/Other/Swiss_master.dta",clear
xtset bfsnr year
keep if reformyear <= 0


///////// Linear models

// Log 
sum pctforeign if F1.diff_voteright_following==1
local mean = `r(mean)'

qui: xtreg log_net_welfare_head c.vf interaction_constant pctforeign ///
	regunemployed_pop lowbracket_rate sp log_rev c.logpop##i.year c.year##i.cantonid if cantonid!=22, fe cl(bfsnr)
nlcom  100*(_b[vf] + `mean'*_b[interaction_constant] ), noheader post
est store L1

qui: xtreg log_net_welfare_head c.vf interaction_constant pctforeign ///
	regunemployed_pop lowbracket_rate sp log_rev  c.logpop##i.year c.year##i.cantonid  if cantonid!=25, fe cl(bfsnr)
nlcom  100*(_b[vf] + `mean'*_b[interaction_constant] ), noheader post
est store L2

qui: xtreg log_net_welfare_head c.vf interaction_constant pctforeign ///
	regunemployed_pop lowbracket_rate sp log_rev  c.logpop##i.year c.year##i.cantonid  if cantonid!=10, fe cl(bfsnr)	
nlcom  100*(_b[vf] + `mean'*_b[interaction_constant] ), noheader post
est store L3

// Net

sum pctforeign if F1.diff_voteright_following==1
local mean = `r(mean)'

qui: xtreg net_welfare_head c.vf interaction_constant pctforeign ///
	regunemployed_pop lowbracket_rate sp log_rev  c.logpop##i.year c.year#i.cantonid if cantonid!=22, fe cl(bfsnr)
nlcom  (_b[vf] + `mean'*_b[interaction_constant] ), noheader post
est store L1b

qui: xtreg net_welfare_head c.vf interaction_constant pctforeign ///
	regunemployed_pop lowbracket_rate sp log_rev  c.logpop##i.year c.year#i.cantonid if cantonid!=25, fe cl(bfsnr)
nlcom  (_b[vf] + `mean'*_b[interaction_constant] ), noheader post
est store L2b

qui: xtreg net_welfare_head c.vf interaction_constant pctforeign ///
	regunemployed_pop lowbracket_rate sp log_rev  c.logpop##i.year c.year#i.cantonid if cantonid!=10, fe cl(bfsnr)	
nlcom  (_b[vf] + `mean'*_b[interaction_constant] ), noheader post
est store L3b

estout L3 L2 L1, cells(b(fmt(2)) se(fmt(2)par))  style(tex)
estout L3b L2b L1b, cells(b(fmt(2)) se(fmt(2)par))  style(tex)


// Bins

// Log
qui: xtreg log_net_welfare_head c.vf##i.foreignbin pctforeign ///
	regunemployed_pop lowbracket_rate sp log_rev  c.logpop##i.year c.year##i.cantonid if cantonid!=22, fe cl(bfsnr)
nlcom  (100*(_b[c.vf#2.foreignbin])) (100*(_b[c.vf#3.foreignbin])) , noheader post
est store BL1

qui: xtreg log_net_welfare_head c.vf##i.foreignbin pctforeign ///
	regunemployed_pop lowbracket_rate sp log_rev  c.logpop##i.year c.year##i.cantonid if cantonid!=25, fe cl(bfsnr)
nlcom  (100*(_b[c.vf#2.foreignbin])) (100*(_b[c.vf#3.foreignbin])), noheader post
est store BL2

qui:xtreg log_net_welfare_head c.vf##i.foreignbin pctforeign ///
	regunemployed_pop lowbracket_rate sp log_rev  c.logpop##i.year c.year##i.cantonid if cantonid!=10, fe cl(bfsnr)
nlcom  (100*(_b[c.vf#2.foreignbin])) (100*(_b[c.vf#3.foreignbin])), noheader post
est store BL3

// Net
qui: xtreg net_welfare_head c.vf##i.foreignbin pctforeign ///
	regunemployed_pop lowbracket_rate sp log_rev  c.logpop##i.year c.year#i.cantonid if cantonid!=22, fe cl(bfsnr)
nlcom  (_b[c.vf#2.foreignbin]) (_b[c.vf#3.foreignbin]), noheader post
est store BL1b

qui:xtreg net_welfare_head c.vf##i.foreignbin pctforeign ///
	regunemployed_pop lowbracket_rate sp log_rev  c.logpop##i.year c.year#i.cantonid if cantonid!=25, fe cl(bfsnr)
nlcom  (_b[c.vf#2.foreignbin]) (_b[c.vf#3.foreignbin]), noheader post
est store BL2b

qui: xtreg net_welfare_head c.vf##i.foreignbin pctforeign ///
	regunemployed_pop lowbracket_rate sp log_rev  c.logpop##i.year c.year#i.cantonid if cantonid!=10, fe cl(bfsnr)
nlcom  (_b[c.vf#2.foreignbin]) (_b[c.vf#3.foreignbin]), noheader post
est store BL3b	
	
estout BL3 BL2 BL1, cells(b(fmt(2)) se(fmt(2)par))  style(tex)
estout BL3b BL2b BL1b, cells(b(fmt(2)) se(fmt(2)par))  style(tex)
	


//////////////////////// //////////////////////// //////////////////////// 
//////////////////////// Table B10
//////////////////////// //////////////////////// //////////////////////// 


use "./Datasets/Other/Swiss_master.dta", clear	
xtset bfsnr year
keep if year<=2007 // Moving out an additional year to allow LT debt to reflect incurred deficits
                               
sum debtperhead, detail
gen log_debt = log(debtperhead + 5924) // Offset

sum pctforeign if F1.diff_voteright_following==1
local mean = `r(mean)'


// Main spec
qui: xtreg log_debt vf interaction_constant pctforeign ///
regunemployed_pop lowbracket_rate sp log_rev c.logpop##c.year  c.year##i.cantonid i.year, fe cl(bfsnr)
nlcom  100*(_b[vf] + `mean'*_b[interaction_constant] ), noheader post
est store S1

// Dropping population outliers
centile pop if F1.diff_voteright_following==1,c(10 90)
qui: xtreg log_debt vf interaction_constant pctforeign ///
	regunemployed_pop lowbracket_rate sp log_rev c.logpop##c.year c.year##i.cantonid i.year if pop > `r(c_1)' & pop < `r(c_2)', fe cl(bfsnr)
nlcom  100*(_b[vf] + `mean'*_b[interaction_constant] ), noheader post
est store S2


// No covars
qui: xtreg log_debt  vf interaction_constant pctforeign ///
	c.logpop##c.year c.year##i.cantonid i.year, fe cl(bfsnr)
nlcom  100*(_b[vf] + `mean'*_b[interaction_constant] ), noheader post
est store S3


// Belgium				
use "./Datasets/Other/Belgium_master.dta", clear
xtset id year
keep if year<=2007

sum pctnoneunoncit if year==2004
local mean = `r(mean)'

// Main Spec
qui: xtreg log_debt_head vf main_interaction filing_rate pctnoneunoncit  ///
socshare log_unemp_rate  c.logpop##c.year  i.year , fe cl(id)
nlcom  100*(_b[vf] + `mean'*_b[main_interaction]), noheader post
est store B1


// Dropping population outliers
qui: centile population if year==2004, c(10 90)
qui: xtreg log_debt_head vf main_interaction pctnoneunoncit  ///
socshare log_unemp_rate  c.logpop##c.year  i.year if population > `r(c_1)' & population <`r(c_2)', fe cl(id)
nlcom  100*(_b[vf] + `mean'*_b[main_interaction]), noheader post
est store B2


// No Covars
qui: xtreg log_debt_head vf main_interaction  ///
c.logpop##c.year   i.year, fe cl(id)
nlcom  100*(_b[vf] + `mean'*_b[main_interaction]), noheader post
est store B3


estout S1 S2 S3 B1 B2 B3, cells(b(fmt(2)) se(fmt(2)par))  style(tex)




//////////////////////// //////////////////////// //////////////////////// 
//////////////////////// Table B11
//////////////////////// //////////////////////// //////////////////////// 


use "./Datasets/Other/Swiss_master.dta", clear	
xtset bfsnr year
keep if reformyear<=1
                              
local svars2 "welfare admin safety education culture transport environment"

foreach x of local svars2{

qui: xtreg gross_`x'_head vf interaction_constant logpop pctforeign i.cantonid##c.year##c.year i.year, fe cl(bfsnr)

qui:sum pctforeign if diff_voteright_following==1
qui:nlcom  (_b[vf]+ `r(mean)'*_b[interaction_constant])  , noheader post
est store S1_`x'

}

estout S1_* , cells(b(fmt(2)) se(fmt(2)par))  
		

		
//////////////////////// //////////////////////// //////////////////////// 
//////////////////////// Table B12
//////////////////////// //////////////////////// //////////////////////// 

		
***** Switzerland
use "./Datasets/Other/Swiss_master.dta",clear
xtset bfsnr year
keep if (reformyear <= 1)  

sum pctforeign if F1.diff_voteright_following==1
local mean = `r(mean)'

centile left if reformyear==-1 & log_net_welfare_head!=.,c(50)
local cutoff = `r(c_1)'

qui:xtreg log_net_welfare_head vf interaction_constant pctforeign ///
regunemployed_pop lowbracket_rate sp log_rev c.year##i.cantonid i.year if left <= `cutoff' & left!=., fe cl(bfsnr)
nlcom  100*(_b[vf] + `mean'*_b[interaction_constant] ), noheader post
est store S1


qui: xtreg log_net_welfare_head vf interaction_constant pctforeign ///
regunemployed_pop lowbracket_rate sp log_rev  c.year##i.cantonid i.year if left >= `cutoff' & left!=., fe cl(bfsnr)
nlcom  100*(_b[vf] + `mean'*_b[interaction_constant] ), noheader post
est store S2

estout S1 S2, cells(b(fmt(2)) se(fmt(2)par))  style(tex)
	
	

**** Belgium 

use "./Datasets/Other/Belgium_master.dta", clear
xtset id year
keep if year<=2006 

sum pctnoneunoncit if year==2004
local mean = `r(mean)'

centile leftshare_begin if year==2004 & log_cpas_head!=., c(50)
local cutoff = `r(c_1)'

qui: xtreg log_cpas_head vf main_interaction filing_rate pctnoneunoncit  ///
socshare log_unemp_rate log_rev c.logpop##c.year  i.year if leftshare_begin <= `cutoff' , fe cl(id)
nlcom  100*(_b[vf] + `mean'*_b[main_interaction]), noheader post
est store B1

qui: xtreg log_cpas_head vf main_interaction filing_rate pctnoneunoncit  ///
socshare log_unemp_rate log_rev c.logpop##c.year  i.year if leftshare_begin >= `cutoff' , fe cl(id)
nlcom  100*(_b[vf] + `mean'*_b[main_interaction]), noheader post
est store B2

estout B1 B2, cells(b(fmt(2)) se(fmt(2)par))  style(tex)
	
